package com.zjc.mymq.broker.utils;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author zjc
 * 简化版本的文件读写工具
 */
public class FileContentUtil {

	public static String readFromFile(String path) {
		try (BufferedReader in = new BufferedReader(new FileReader(path))) {
			StringBuffer stb = new StringBuffer();
			while (in.ready()) {
				stb.append(in.readLine());
			}
			return stb.toString();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static void overWriteToFile(String path, String content) {
		try (FileWriter fileWriter = new FileWriter(path)) {
			fileWriter.write(content);
			fileWriter.flush();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

//    public static void main(String[] args) {
//        String content = FileContentReaderUtil.readFromFile("D:/JAVAWEB/my_project/mymq/broker/config/myMq-topic.json");
//        System.out.println(content);
//        List<MyMqTopicModel> myMqTopicModelList = JSON.parseArray(content, MyMqTopicModel.class);
//        System.out.println(myMqTopicModelList);
//    }
}
